home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ für Kids
/
C++ for kids.iso
/
Buch
/
Obutton1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-22
|
3KB
|
94 lines
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "Obutton1.h"
TColor OColor[4] =
{clBlack, clGray, clSilver, clWhite};
//---------------------------------------------------------------------------
static inline TOButton *ValidCtrCheck()
{
return new TOButton(NULL);
}
//---------------------------------------------------------------------------
__fastcall TOButton::TOButton(TComponent* Owner)
: TCustomControl(Owner)
{
Color = clBtnFace;
SetSize (Rect (0, 0, 50, 50));
Pressed = false;
}
//---------------------------------------------------------------------------
namespace Obutton1
{
void __fastcall Register()
{
TComponentClass classes[1] = {__classid(TOButton)};
RegisterComponents("ZusΣtzlich", classes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TOButton::SetSize (TRect Rechteck)
{
Left = Rechteck.Left;
Top = Rechteck.Top;
Width = Rechteck.Right - Rechteck.Left;
Height = Rechteck.Bottom - Rechteck.Top;
}
//---------------------------------------------------------------------------
void __fastcall TOButton::SetColor(TColor OBrush, TColor OPen)
{
Canvas->Brush->Color = OBrush;
Canvas->Pen->Color = OPen;
}
//---------------------------------------------------------------------------
void __fastcall TOButton::MouseDown
(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
TCustomControl::MouseDown (Button, Shift, X, Y);
if (Button == mbLeft)
{
Pressed = true;
Paint ();
}
}
//---------------------------------------------------------------------------
void __fastcall TOButton::MouseUp
(TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
TCustomControl::MouseUp (Button, Shift, X, Y);
Pressed = false;
Paint ();
}
//---------------------------------------------------------------------------
void __fastcall TOButton::Paint (void)
{
// Liniendicke
Canvas->Pen->Width = 2;
// OButton gedrⁿckt
if (Pressed)
{
for (int i=1; i<5; i++)
{
SetColor (OColor[(i-1)/2], OColor[(i-1)/2]);
Canvas->Arc (i, i, Width-i, Height-i, i, i, i, i);
}
}
// OButton nicht gedrⁿckt
else
{
for (int i=1; i<5; i++)
{
SetColor (OColor[i-1], OColor[i-1]);
Canvas->Arc (i, i, Width-i, Height-i, i, i, i, i);
}
}
// OButton-FlΣche
SetColor (Color, Color);
Canvas->Ellipse (5, 5, Width-5, Height-5);
}
//---------------------------------------------------------------------------